"""
    第三方微博登录接口
"""
from urllib.parse import urlencode

class OAuthWeiBoAPI:
    def __init__(self, app_key, app_secret, redirect_uri):
        self.app_key = app_key
        self.app_secret = app_secret
        self.redirect_uri = redirect_uri # 回调地址

    def get_grant_url(self):
        """
        获取微博授权登录页的url地址[接口文档]
        """
        params = {
            "client_id": self.app_key,
            "redirect_uri": self.redirect_uri,
            "response_type": "code",
        }

        return "https://api.weibo.com/oauth2/authorize?" + urlencode(params)


if __name__ == '__main__':
    config = {
        "app_key": "706848276",
        "app_secret": "bf1e3b463d5218c071a786c3cd8a7e23",
        "redirect_uri": "http://localhost:7000/dadashop/templates/callback.html",
    }

    weibo_api = OAuthWeiBoAPI(**config)
    print(weibo_api.get_grant_url())















